<?php
// +----------------------------------------------------------------------
// | Description: 规则
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller\purchasing;

use app\admin\controller\ApiCommon;

class Post extends ApiCommon
{

    public function index()
    {
        $Model = model('purchasing.post');
        $param = $this->param;
        $id = !empty($param['id']) ? $param['id']: '';
        $data = $Model->getDataList($id,$param);
        return resultArray(['data' => $data]);
    }
    public function save()
    {
        $Model = model('purchasing.post');
        $param = $this->param;
        $data = $Model->createData($param);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '添加成功']);
    }

    public function update()
    {
        $Model = model('purchasing.post');
        $param = $this->param;
        unset($param['user_id']);
        unset($param['structure_id']);
        unset($param['serial']);
        unset($param['type']);
        $data = $Model->updateDataById($param, $param['id']);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '编辑成功']);
    }

    public function delete()
    {
        $Model = model('purchasing.post');
        $param = $this->param;
        $data = $Model->delDataById($param['id'], false);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '删除成功']);
    }

    public function getBidTime()
    {
        $Model = model('purchasing.post');
        $param = $this->param;
        $data = $Model->getBidTime($param);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => $data]);
    }
    public function updateRequirements()
    {
        $Model = model('purchasing.post');
        $param = $this->param;
        if(empty($param['id'])){
            return resultArray(['error' => '致命错误 code：0x00004']);
        }
        $data = $Model->updateDataById($param['id'],$param);
        if (!$data) {
            return resultArray(['error' => $Model->getError()]);
        }
        return resultArray(['data' => '编辑成功']);
    }

}
